package com.cloudwebrtc.voip.sipenginev2.impl;

import com.cloudwebrtc.voip.sipenginev2.Call;
import com.cloudwebrtc.voip.sipenginev2.CallManager;
import com.cloudwebrtc.voip.sipenginev2.CallStateEventListener;
import com.cloudwebrtc.voip.sipenginev2.SipProfile;

public class CallManagerImpl implements CallManager {
	//implement for CallManager_JNI.cpp
	private long nativePtr = 0;
	private native long MakeCall(long nativePtr, long profilePtr, String called,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled);
	private native long MakeCall2(long nativePtr, String display_name, String uri,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled);
	private native long MakeCall3(long nativePtr, long profilePtr, String called,String device_type,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled);
	private native boolean RegisterCallStateObserver(long nativePtr,CallStateEventListener observer);
	private native void DeRegisterCallStateObserver(long nativePtr);
	private native void SetMaxConcurrentCall(long nativePtr,int num);
	private native boolean HangupAllCalls(long nativePtr);
	
	public CallManagerImpl(long aNativePtr)
	{
		nativePtr = aNativePtr;
	}

	@Override
	public Call MakeCall(SipProfile profile, String called,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled) {
		SipProfileImpl profile_impl = (SipProfileImpl)profile;
		long callPtr = MakeCall(nativePtr,profile_impl.GetNativePtr(),called,audio_enabled,video_enabled,data_enabled);
		if(callPtr!=0)
			return new CallImpl(callPtr);
		return null;
	}

	@Override
	public Call MakeCall(String display_name, String uri,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled) {
		long callPtr =  MakeCall2(nativePtr,display_name,uri,audio_enabled,video_enabled,data_enabled);
		if(callPtr!=0)
			return new CallImpl(callPtr);
		return null;
	}
	
	@Override
	public Call MakeCall(SipProfile profile, String called, String device_type,
			boolean audio_enabled, boolean video_enabled, boolean data_enabled) {
		SipProfileImpl profile_impl = (SipProfileImpl)profile;
		long callPtr = MakeCall3(nativePtr,profile_impl.GetNativePtr(),called,device_type,audio_enabled,video_enabled,data_enabled);
		if(callPtr!=0)
			return new CallImpl(callPtr);
		return null;
	}

	@Override
	public boolean RegisterCallStateObserver(CallStateEventListener observer) {
		return RegisterCallStateObserver(nativePtr,observer);
	}

	@Override
	public void DeRegisterCallStateObserver() {
		DeRegisterCallStateObserver(nativePtr);
	}

	@Override
	public void SetMaxConcurrentCall(int num) {
		SetMaxConcurrentCall(nativePtr,num);
	}
	
	@Override
	public boolean HangupAllCalls()
	{
		return HangupAllCalls(nativePtr);
	}
}
